//app.js
App({
  data: {
  },
  // 接口地址
  api: {
    // binding: "http://10.100.223.111:8899/register/api/authorize/binding",//登录
    // getUserToken: "http://10.100.223.111:8899/register/api/authorize/getUserToken",//新建token
    // refreshToken: "http://10.100.223.111:8899/register/api/authorize/refreshToken",//刷新token
    //unbinding: "http://10.100.223.111:8899/register/api/authorize/unbinding", //解绑

    // getUserInfo: "http://10.100.223.111:8899/register/api/selfExaminationEnroll/index",//index首页
    // getExamineSchool: "http://10.100.223.111:8899/register/api/selfExaminationEnroll/listExamineSchool",//获取本科院校
    // getMajor: "http://10.100.223.111:8899/register/api/selfExaminationEnroll/listMajor",//本科专业
    // submit: "http://10.100.223.111:8899/register/api/selfExaminationEnroll/save",//提交报名
    
    binding: "https://m.szpt.edu.cn/register/api/authorize/binding",//登录
    getUserToken: "https://m.szpt.edu.cn/register/api/authorize/getUserToken",//新建token
    refreshToken: "https://m.szpt.edu.cn/register/api/authorize/refreshToken",//刷新token
    unbinding:"https://m.szpt.edu.cn/register/api/authorize/unbinding", //解绑
    getUserInfo: "https://m.szpt.edu.cn/register/api/selfExaminationEnroll/index",//index首页
    getExamineSchool: "https://m.szpt.edu.cn/register/api/selfExaminationEnroll/listExamineSchool",//获取本科院校
    getMajor: "https://m.szpt.edu.cn/register/api/selfExaminationEnroll/listMajor",//本科专业
    submit: "https://m.szpt.edu.cn/register/api/selfExaminationEnroll/save",//提交报名
  },
  onLaunch: function (options) {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    var token = wx.getStorageSync('token');
    // 登录 
    wx.login({
      success: function (res) {
        // console.log(res);
        if (res.code) {
          console.log('获取code', res.code);
          wx.setStorageSync('wxCode', res.code)
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    });
    console.log('这是app.js的token' + token);
    wx.getSetting({
      success: res => {
        console.log('全局 authSetting.scope.userInfo', res);
        if (token) {
        // if (res.authSetting.scope.userInfo) {
          console.log('已授权去首页');
          wx.reLaunch({
            url: '/pages/index/index'
          })
        } else {
          // 未授权，跳转到授权页面
          console.log("未授权");

          wx.reLaunch({
            url: '/pages/login/login'
          })

        }
      },
    })
   
    },

  globalData: {
    userInfo: null,
  },
})